package com.lwy.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lwy.dao.BookStateMapper;
import com.lwy.entity.BookState;
import com.lwy.service.impl.BookStateServiceImpl;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

//状态表contorller控制层
@RestController
@RequestMapping("state")
public class BookStateController  {

    @Resource
    private BookStateServiceImpl bookStateService;

    @Resource
    private BookStateMapper bookStateMapper;


    @RequestMapping("findById")
    public Integer find(Integer user_id,Integer nove_id){
        List<BookState> bookStates = bookStateService.list(new QueryWrapper<BookState>().eq("user_id", user_id).eq("nove_id",nove_id));
        if(bookStates.size()>0){
            return 1;
        }else{
            return 0;
        }
    }

    @RequestMapping("findByOrder")
    public BookState findOrder(Integer user_id,Integer nove_id){
        return bookStateMapper.findByOrder(user_id,nove_id);
    }
//    保存方法
    @RequestMapping("save")
    public boolean save(BookState bookState){
        return bookStateService.save(bookState);
    }

//    删除方法
    @RequestMapping("deleteUid")
    public Integer del(Integer user_id,Integer nove_id){
        return bookStateMapper.deleteUid(user_id,nove_id);
    }
}
